package com.dyz.leetcode._07_hashSearch;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;

public class _49_groupAnagrams {
    public List<List<String>> groupAnagrams(String[] strs) {
        HashMap<String, List<String>> map = new HashMap<>();

        for(String s:strs){
            char [] ch = s.toCharArray();
            Arrays.sort(ch);
            String ns = String.valueOf(ch);
            if(!map.containsKey(ns)){map.put(ns, new ArrayList<>());}
            map.get(ns).add(s);
        }
        return new ArrayList<>(map.values());
    }
}
